package cn.deschen.search.constants;

/**
 * @Author hanbin_chen
 * @Description 数据表名枚举
 * @DateTime 2021/06/17
 * @Version V1.0.0
 */
public enum TableInfo {
    NAME_AD_PLAN("ad_db","ad_plan"),
    NAME_AD_CREATIVE("ad_db","ad_creative"),
    NAME_AD_UNIT("ad_db","ad_unit"),
    NAME_AD_TAG("ad_db","ad_tag"),
    NAME_AD_KEYWORD("ad_db","ad_keyword"),
    NAME_AD_REGION("ad_db","ad_region"),
    NAME_AD_UNIT_ELE("ad_db","ad_unit_ele"),

    ;

    private String datasource;

    private String tableName;

    TableInfo(String datasource, String tableName) {
        this.datasource = datasource;
        this.tableName = tableName;
    }

    public String getDatasource() {
        return datasource;
    }

    public String getTableName() {
        return tableName;
    }

    /**
     * 根据value返回枚举类型
     *
     * @param datasource 数据库名
     * @param tableName 数据表名
     * @return
     */
    public static TableInfo get(String datasource, String tableName) {
        for (TableInfo tableInfo : values()) {
            if (tableInfo.getDatasource().equals(datasource)
                    && tableInfo.getTableName().equals(tableName)) {
                return tableInfo;
            }
        }
        return null;
    }
}
